import { combineReducers } from "redux";
import * as types from "./actionTypes";

const openRegisterReducer = (state = false, action) => {
    switch (action.type) {
        case types.IS_OPEN_REGISTER:
            return action.data;
        default:
            return state;
    }
};
const openLoginReducer = (state = false, action) => {
    switch (action.type) {
        case types.IS_OPEN_LOGIN:
            return action.data;
        default:
            return state;
    }
};
const openCreateTaskReducer = (state = false, action) => {
    switch (action.type) {
        case types.IS_OPEN_CREATE_TASK:
            return action.data;
        default:
            return state;
    }
};

const loginProfileReducer = (state = {}, action) => {
    switch (action.type) {
        case types.LOGIN_USER_PROFILE:
            return {
                ...state,
                ...action.data,
            };
        default:
            return state;
    }
};

const getTaskListReducer = (state = [], action) => {
    switch (action.type) {
        case types.GET_TASK_LIST:
            return [...action.data];
        default:
            return state;
    }
};

const exitLoginReducer = (state = false, action) => {
    switch (action.type) {
        case types.EXIT_LOGIN:
            return action.data;
        default:
            return state;
    }
};

const paymentReducer = (state = false, action) => {
    switch (action.type) {
        case types.PAYMENT:
            return action.data;
        default:
            return state;
    }
};

const getGMoneyReducer = (state = 0, action) => {
    switch (action.type) {
        case types.GET_GMONEY:
            return action.data;
        default:
            return state;
    }
};

const initRechargeRecordState = {
    onePage: [],
    rechargeRecord: [],
};
const rechargeRecordReducer = (state = initRechargeRecordState, action) => {
    switch (action.type) {
        case types.RECHARGE_RECORD:
            return {
                ...state,
                ...action.data,
            };
        default:
            return state;
    }
};

const initConsumeDetailsState = {
    onePage: [],
    consumeDetails: [],
};
const consumeDetailsReducer = (state = initConsumeDetailsState, action) => {
    switch (action.type) {
        case types.CONSUME_DETAILS:
            return {
                ...state,
                ...action.data,
            };
        default:
            return state;
    }
};

const onSellGoodsReducer = (state = false, action) => {
    switch (action.type) {
        case types.ON_SELL_GOODS:
            return action.data;
        default:
            return state;
    }
};

const getMyGoodsReducer = (state = [], action) => {
    switch (action.type) {
        case types.GET_MY_GOODS:
            return action.data;
        default:
            return state;
    }
};

const operationMyGoddsReducer = (state = false, action) => {
    switch (action.type) {
        case types.OPERATION_MY_GOODS:
            return action.data;
        default:
            return state;
    }
};

const payGmoneyReducer = (state = false, action) => {
    switch (action.type) {
        case types.PAY_GMONEY:
            return action.data;
        default:
            return state;
    }
};

const addCartReducer = (state = false, action) => {
    switch (action.type) {
        case types.ADD_CART:
            return action.data;
        default:
            return state;
    }
};

const firstJoinChatReducer = (state = 0, action) => {
    switch (action.type) {
        case types.GET_FIRST_JOIN_CHAT:
            return action.data;
        default:
            return state;
    }
};

const getSingleGoodsIdReducer = (state = {}, action) => {
    switch (action.type) {
        case types.GET_SINGLE_GOODSID:
            return {
                ...state,
                ...action.data,
            };
        default:
            return state;
    }
};

const contentListReducer = (state = [], action) => {
    switch (action.type) {
        case types.GET_CONTENT_LIST:
            return action.data;
        // case types.RECEIVE_MSG:
        //   return [...state, action.data]
        default:
            return state;
    }
};

const chatUsersListReducer = (state = [], action) => {
    switch (action.type) {
        case types.GET_CHAT_USERS_LIST:
            return action.data;
        default:
            return state;
    }
};

const changeManyToReadReducer = (state = false, action) => {
    switch (action.type) {
        case types.CHANGE_MANY_TO_READ:
            return action.data;
        default:
            return state;
    }
};

// const realTimeReadMsgReducer = (state = {}, action) => {
//   switch (action.type) {
//     case types.REAL_TIME_READ_MSG:
//       return action.data
//     default:
//       return state
//   }
// }

const reducers = combineReducers({
    openRegisterReducer,
    openLoginReducer,
    openCreateTaskReducer,
    loginProfileReducer,
    getTaskListReducer,
    exitLoginReducer,
    paymentReducer,
    getGMoneyReducer,
    rechargeRecordReducer,
    consumeDetailsReducer,
    onSellGoodsReducer,
    getMyGoodsReducer,
    operationMyGoddsReducer,
    payGmoneyReducer,
    addCartReducer,
    firstJoinChatReducer,
    getSingleGoodsIdReducer,
    contentListReducer,
    chatUsersListReducer,
    changeManyToReadReducer,
    // realTimeReadMsgReducer,
});

export default reducers;
